package com.ating.demo.Service;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.ating.demo.Entity.Article;
import com.ating.demo.Mapper.ArticleMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ArticleService {
    @Resource
    private ArticleMapper articleMapper;

    public List<Article> selectAll(Article article){
        return articleMapper.selectAll(article);
    }

    public Article selectOne(Integer id){
        return articleMapper.selectById(id);
    }


    public PageInfo<Article> selectPage(Integer PageSize, Integer PageNum, Article article){
        PageHelper.startPage(PageNum,PageSize);
        List<Article> list = articleMapper.selectAll(article);
        return PageInfo.of(list);
    }

    public void add(Article article){
        article.setTime(DateUtil.now());//获取当前时间字符串
        articleMapper.insert(article);
    }

    public void update(Article article){
        articleMapper.updateById(article);
    }

    public void moveById(Integer id){
        articleMapper.moveById(id);
    }

    public Integer selectCountByDate(String date){
        return articleMapper.selectCountByDate(date);
    }
}
